Ext.onReady(function(){
    var loginForm = new Ext.FormPanel({
        labelWidth: 50, // label settings here cascade unless overridden
        url:'${pageContext.request.contextPath}/userAction!test.action',
        frame:true,
        //title: 'none',
        bodyStyle:'padding:5px 5px 0',
        width: 350,
        defaults: {width: 230},
        defaultType: 'textfield',

        items: [{
                fieldLabel: '账号',
                name: 'name',
                allowBlank:false,
                emptyText:"天下账号",
                blackText:"姓名不能为空"
            },{
                fieldLabel: '密码',
                name: 'pwd'
            }
        ],

        buttons: [{
            text:'注册',
            disabled:false,
            handler:function(){  
            	win.hide();
            	registWin.show();
            }  
        },
        {
            text:'登录',
            disabled:false,
            handler:function(){  
            	loginForm.getForm().submit({  
                    success:function(form,action){  
                        Ext.Msg.alert('消息',action.result.msg); 
                        wind.hide();
                    },  
                    failure:function(){  
                        Ext.Msg.alert('消息','失败');  
                    }  
                });  
            }  
        },{
            text: '取消',
            handler: function(){
                win.hide();
            }
        }]
    });
    
    var win = new Ext.Window({
        applyTo:viewport,
        layout:'fit',
        width:500,
        height:300,
        closeAction:'hide',
        plain: true,
        items: loginForm
    });
	
    //注册页面
     var registForm = new Ext.FormPanel({
         labelWidth: 50, // label settings here cascade unless overridden
         url:'${pageContext.request.contextPath}/userAction!reg.action',
         frame:true,
         //title: 'none',
         bodyStyle:'padding:5px 5px 0',
         width: 350,
         defaults: {width: 230},
         defaultType: 'textfield',

         items: [{
                 fieldLabel: '账号',
                 name: 'name',
                 allowBlank:false
             },{
                 fieldLabel: '密码',
                 name: 'pwd',
                 vtype:"email"
             },{
                 fieldLabel: '密码',
                 name: 'pwd2'
             }
         ],

         buttons: [{
             text:'登录',
             disabled:false,
             handler:function(){  
             	registWin.hide();
             	wind.show();
             }  
         },
         {
             text:'注册',
             disabled:false,
             handler:function(){  
             	registForm.getForm().submit({  
                     success:function(form,action){  
                         Ext.Msg.alert('消息',action.result.msg);
                         registWin.hide();
                      	 wind.show();
                     },  
                     failure:function(){  
                         Ext.Msg.alert('消息','失败');  
                     }  
                 });  
             }  
         },{
             text: '取消',
             handler: function(){
             	registWin.hide();
             }
         }]
     });
     
     var viewport = new Ext.Viewport({
	      layout : 'border',
	      renderTo : "form1",// 呈现
	      items:[{
	          region : 'center',
	          title:"信息展示区域",
	          id : "tab",
	          xtype:'panel',
	          items:[registWin,win]
	        	  
	      }]
     });
    
     var registWin = new Ext.Window({
         applyTo:viewport,
         layout:'fit',
         width:500,
         height:300,
         closeAction:'hide',
         plain: true,
         items: registForm
     });

    var button = Ext.get('show-btn');
    button.on('click', function(){
    	alert(1);
        win.show(this);
    });     
});